jQuery.fn.createUpload=function (type, server) {

    this.each(function() {
        var $list = $(this).find('.uploader-list'),
            pick  = '#'+$(this).find('.picker').attr('id'),
            name  = $(this).attr('name');
        //获取token
    $.get("index.php?s=/admin/qiniu/uptoken.html",function(data){//ajax start
        
        var obj=$.parseJSON(data);
        var uploader = new WebUploader.Uploader({
            server: server,
            pick: pick,
            // 其他配置项
            auto: true,
            compress:false,
            allowMagnify: false,
            formData:{
            "token":obj.token,
            "x:url":obj.url,
            },
        });
            
        uploader.onFileQueued = function( file ) {
            if(type == 'one'){
                $list.html( '<div id="' + file.id + '" class="item">' +
                    '<h4 class="info">' + file.name + '</h4>' +
                    '<p class="state">等待上传...</p>' +
                '</div>' );
            }else if(type == 'list'){
                $list.append( '<div id="' + file.id + '" class="item">' +
                    '<h4 class="info">' + file.name + '</h4>' +
                    '<p class="state">等待上传...</p>' +
                '</div>' );
            }else{
                $list.html( '<div id="' + file.id + '" class="item">' +
                    '<h4 class="info">' + file.name + '</h4>' +
                    '<p class="state">等待上传...</p>' +
                '</div>' );
            }
        };
        // 文件上传过程中创建进度条实时显示。
        uploader.on( 'uploadProgress', function( file, percentage ) {
        });

        // 文件上传成功，给item添加成功class, 用样式标记上传成功。
        uploader.on( 'uploadSuccess', function(file,json) {

            if(type == 'one'){
                $( '#'+file.id ).html('<input type="hidden" name="'+name+'" value="'+json.savename+'">'+
                    '<image style="max-width:100px;max-height:100px" src="'+decodeURIComponent(json.savepath)+json.savename+'" />'+
                    '<a href="index.php?s=/admin/qiniu/del.html&name='+json.savename+'" class="remove-img"><i class="fa fa-remove"></i>删除图片</a>'
                    );
                   
            }else if(type == 'list'){
                $( '#'+file.id ).html('<input type="hidden" name="'+name+'[]" value="'+json.savename+'">'+
                    '<image style="max-width:100px;max-height:100px" src="'+decodeURIComponent(json.savepath)+json.savename+'" />'+
                    '<a href="index.php?s=/admin/qiniu/del.html&name='+json.savename+'" class="remove-img"><i class="fa fa-remove"></i>删除图片</a>'
                    );
            }else if(type == 'ex_one'){
                $('.ex-pick').html('<img style="widht:50px;height:50px;" src="../public/uploads/member/'+json.savename+'"/>');
                $('#get_img').val(json.savename);
                $.post("index.php?s=/index/index/edit_headimg.html",{img:json.savename},function(data){}); 
     
            }else{
                $( '#'+file.id ).html('<input type="hidden" name="'+name+'" value="'+json.savename+'">'+
                    '<a href="/'+json.savepath+json.savename+'">下载('+json.savename+')</a>&nbsp&nbsp&nbsp'+
                    '<a class="remove-img"><i class="fa fa-remove"></i>删除</a>'
                    );
            }
            $('.remove-img').click(function(){
                $(this).parent().remove();
                });
        });

        // 文件上传失败，现实上传出错。
        uploader.on( 'uploadError', function( file ) {
            var $li = $( '#'+file.id ),
                $error = $li.find('div.error');

            // 避免重复创建
            if ( !$error.length ) {
                $error = $('<div class="error"></div>').appendTo( $li );
            }
            $error.text('上传失败');
        });
    });



    $('.remove-img').click(function(){
        $(this).parent().remove();
        });

         });//ajax end

};

